﻿using System;
using System.Configuration;

using Business.Entities.Configuration;
using Business.Components.PendingChangesAlerts;

namespace TfsPendingCheckinAlerts
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfigurationProperties oConfigurationProperties = loadConfigurationProperties();

            PendingChanges oPendingChanges = new PendingChanges(oConfigurationProperties);
            oPendingChanges.sendAlerts();
        }

        private static ConfigurationProperties loadConfigurationProperties()
        {
            ConfigurationProperties oConfigurationProperties = new ConfigurationProperties();

            oConfigurationProperties.TfsServer = ConfigurationManager.AppSettings["str_tfs_server"];
            oConfigurationProperties.AdDomain = ConfigurationManager.AppSettings["str_ad_domain"];
            oConfigurationProperties.NotifyAdministrators = bool.Parse(ConfigurationManager.AppSettings["bln_notify_administrators"]);
            oConfigurationProperties.NotifyUsers = bool.Parse(ConfigurationManager.AppSettings["bln_notify_user"]);
            oConfigurationProperties.HtmlMail = bool.Parse(ConfigurationManager.AppSettings["bln_html_mail"]);
            oConfigurationProperties.LogPath = ConfigurationManager.AppSettings["str_log_path"];
            oConfigurationProperties.TemplatesPath = ConfigurationManager.AppSettings["str_templates_path"];
            oConfigurationProperties.Culture = ConfigurationManager.AppSettings["str_culture"];

            string str_administrators_email = ConfigurationManager.AppSettings["str_administrators_email"];
            oConfigurationProperties.AdministratorEmails = str_administrators_email.Split(new Char[] { ' ', ',', ';', '|' });

            oConfigurationProperties.ConnectionString = ConfigurationManager.ConnectionStrings["db_tfs_pending_checkin"].ConnectionString;
            
            return oConfigurationProperties;
        }
    }
}